package com.person.yhzs.common;


import io.swagger.annotations.ApiModelProperty;

public class ReturnData {

    /**
     * 成功
     */
    public static final int CODE_OK = 200;
    /**
     * 请求报文存在语法错误
     */
    public static final int BAD_REQUEST = 400;
    /**
     * 未授权
     */
    public static final int CODE_UNAUTHORIZED = 401;
    /**
     * 已授权
     */
    public static final int CODE_HAS_AUTHORIZED = 4012;
    /**
     * 授权验证失败
     */
    public static final int CODE_AUTH_FAIL = 4011;
    /**
     * 无权限访问
     */
    public static final int CODE_FORBIDDEN = 403;
    /**
     * 页面不存在
     */
    public static final int CODE_NOT_FOUND = 404;
    /**
     * 不支持此操作
     */
    public static final int CODE_NOT_SUPPORTED = 405;
    /**
     * 无效数据
     */
    public static final int CODE_INVALID_DATA = 420;
    /**
     * 服务器错误
     */
    public static final int CODE_FAIL = 500;
    /**
     * 緩存token出現错误
     */
    public static final int CODE_FAIL_CACHE_TOKEN = 530;

    @ApiModelProperty(value = "返回处理结果代码", required = true)
    private int code;

   @ApiModelProperty(value = "返回处理结果信息")
    private String message;

    @ApiModelProperty(value = "返回处理结果数据")
    private Object data;

    public ReturnData(int code) {
        this.code = code;
    }

    public ReturnData(Object data) {
        this.data = data;
    }

    public ReturnData(String message) {
        this.message = message;
    }

    public ReturnData(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static  ReturnData ok() {
        return new ReturnData(CODE_OK);
    }

    public static  ReturnData fail(String message) {
        ReturnData returnData = new ReturnData(CODE_FAIL);
        returnData.message = message;
        return returnData;
    }

    public static  ReturnData ok(String message) {
        ReturnData returnData = new ReturnData(CODE_OK);
        returnData.message = message;
        return returnData;
    }

    public static  ReturnData ok(Object data) {
        ReturnData returnData = new ReturnData(data);
        returnData.setCode(CODE_OK);
        return returnData;
    }

    public static  ReturnData ok(String message,Object data) {
        ReturnData returnData = new ReturnData(CODE_OK);
        returnData.message = message;
        returnData.data = data;
        return returnData;
    }

    public int getCode() {
        return code;
    }

    public ReturnData setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ReturnData setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ReturnData setData(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ReturnData{");
        sb.append("code=").append(code);
        sb.append(", message='").append(message).append('\'');
        sb.append(", data=").append(data);
        sb.append('}');
        return sb.toString();
    }
}
